/*
 *	千航正文编辑控件中自定义的菜单及相关的方法  
 */

//************** 菜单ID常量 *******************
var CustomMenuID_Separators = [];

var CustomMenuID_AddLocalSign = 0;//添加本地印章
var CustomMenuID_AddURLSign = 1;//添加远程印章
var CustomMenuID_ReSign = 100;//重新盖章

var CustomMenuID_AddIndividualSign = 2;//添加个人签名
var CustomMenuID_AddHandSign = 3;//添加手写签名
var CustomMenuID_AddDigitalSign = 4;//添加数字签名
var CustomMenuID_ReAddDigitalSign = 5;//重新数字签名

CustomMenuID_Separators[0] = 6;//分隔符

var CustomMenuID_CheckSign = 7;//印章签名验证
var CustomMenuID_ProtectSign = 8;//保护印章签名
var CustomMenuID_UnProtectSign = 9;//取消保护
var CustomMenuID_CheckDigitalSign = 10;//验证数字签名

CustomMenuID_Separators[1] = 11;//分隔符

var CustomMenuID_AcceptRevisions = 12;//接受修订 去掉痕迹
var CustomMenuID_CancelRevisions = 13;//重新修订 恢复痕迹
var CustomMenuID_TemplateRedhead = 14;//模板套红
var CustomMenuID_ShowRevisions = 15;//痕迹(显示/隐藏)

CustomMenuID_Separators[2] = 16;//分隔符

var CustomMenuID_ProtectDocument = 17;//文档保护
var CustomMenuID_UnProtectDocument = 18;//取消文档保护

var CustomMenuIDs = new Array();//把菜单ID放到一个数组里
CustomMenuIDs.push(CustomMenuID_AddLocalSign, CustomMenuID_AddURLSign, CustomMenuID_AddIndividualSign);
CustomMenuIDs.push(CustomMenuID_AddHandSign, CustomMenuID_AddDigitalSign, CustomMenuID_ReAddDigitalSign);
CustomMenuIDs.push(CustomMenuID_Separators[0], CustomMenuID_CheckSign, CustomMenuID_ProtectSign);
CustomMenuIDs.push(CustomMenuID_UnProtectSign, CustomMenuID_CheckDigitalSign, CustomMenuID_Separators[1]);
CustomMenuIDs.push(CustomMenuID_AcceptRevisions, CustomMenuID_CancelRevisions, CustomMenuID_TemplateRedhead);
CustomMenuIDs.push(CustomMenuID_ShowRevisions, CustomMenuID_Separators[2], CustomMenuID_ProtectDocument);
CustomMenuIDs.push(CustomMenuID_UnProtectDocument);
//*********************************************

//************** 菜单key常量 *******************
var CustomMenuKey_AddLocalSign = 1;//添加本地印章
var CustomMenuKey_AddURLSign = 2;//添加远程印章
var CustomMenuKey_ReSign = 100;//重新盖章

var CustomMenuKey_AddIndividualSign = 3;//添加个人签名
var CustomMenuKey_AddHandSign = 4;//添加手写签名
var CustomMenuKey_AddDigitalSign = 23;//添加数字签名
var CustomMenuKey_ReAddDigitalSign = 24;//重新数字签名

var CustomMenuKey_CheckSign = 5;//印章签名验证
var CustomMenuKey_ProtectSign = 6;//保护印章签名
var CustomMenuKey_UnProtectSign = 7;//取消保护
var CustomMenuKey_CheckDigitalSign = 25;//验证数字签名

var CustomMenuKey_AcceptRevisions = 12;//接受修订 去掉痕迹
var CustomMenuKey_CancelRevisions = 34;//重新修订 恢复痕迹
var CustomMenuKey_TemplateRedhead = 13;//模板套红
var CustomMenuKey_ShowRevisions = 27;//痕迹(显示/隐藏)

var CustomMenuKey_ProtectDocument = 32;//文档保护
var CustomMenuKey_UnProtectDocument = 33;//取消文档保护
 
//创建自定义菜单
function createCustomMenu(index,menuCaption) {
	TANGER_OCX_OBJ.AddCustomMenu2(index,menuCaption);
}


//初始化自定义菜单
function initCustomMenu() {
    //创建自定义菜单
	createCustomMenu(0," 安全(S) ");

	//印章控制
	TANGER_OCX_AddCustomMenuItem(CustomMenuID_AddLocalSign, '添加本地印章', CustomMenuKey_AddLocalSign);
	TANGER_OCX_AddCustomMenuItem(CustomMenuID_AddURLSign, '添加远程印章', CustomMenuKey_AddURLSign);

	TANGER_OCX_AddCustomMenuItem(CustomMenuID_AddIndividualSign, '添加个人签名', CustomMenuKey_AddIndividualSign);
	TANGER_OCX_AddCustomMenuItem(CustomMenuID_AddHandSign, '添加手写签名', CustomMenuKey_AddHandSign);
	TANGER_OCX_AddCustomMenuItem(CustomMenuID_AddDigitalSign, '添加数字签名', CustomMenuKey_AddDigitalSign);
	TANGER_OCX_AddCustomMenuItem(CustomMenuID_ReAddDigitalSign, '重新数字签名', CustomMenuKey_ReAddDigitalSign);

	TANGER_OCX_AddCustomSeparator(CustomMenuID_Separators[0]);

	TANGER_OCX_AddCustomMenuItem(CustomMenuID_CheckSign, '印章签名验证', CustomMenuKey_CheckSign);
	TANGER_OCX_AddCustomMenuItem(CustomMenuID_ProtectSign, '保护印章签名', CustomMenuKey_ProtectSign);
	TANGER_OCX_AddCustomMenuItem(CustomMenuID_UnProtectSign, '取消保护', CustomMenuKey_UnProtectSign);
	TANGER_OCX_AddCustomMenuItem(CustomMenuID_CheckDigitalSign, '验证数字签名', CustomMenuKey_CheckDigitalSign);

	TANGER_OCX_AddCustomSeparator(CustomMenuID_Separators[1]);

	TANGER_OCX_AddCustomMenuItem(CustomMenuID_AcceptRevisions, '接受修订 去掉痕迹', CustomMenuKey_AcceptRevisions);
	TANGER_OCX_AddCustomMenuItem(CustomMenuID_CancelRevisions, '重新修订 恢复痕迹', CustomMenuKey_CancelRevisions);
	//套红控制
	TANGER_OCX_AddCustomMenuItem(CustomMenuID_TemplateRedhead, '模板套红', CustomMenuKey_TemplateRedhead);
	TANGER_OCX_AddCustomMenuItem(CustomMenuID_ShowRevisions, '痕迹(显示/隐藏)', CustomMenuKey_ShowRevisions);

	// 文档保护
	TANGER_OCX_AddCustomSeparator(CustomMenuID_Separators[2]);
	TANGER_OCX_AddCustomMenuItem(CustomMenuID_ProtectDocument, '文档保护', CustomMenuKey_ProtectDocument);
	TANGER_OCX_AddCustomMenuItem(CustomMenuID_UnProtectDocument, '取消文档保护', CustomMenuKey_UnProtectDocument);

	//置所有菜单无效
	disableAll();
}

//置所有自定义菜单无效
function disableAll() {
	for (var i = 0; i < CustomMenuIDs.length; i++) {
		TANGER_OCX_EnableCustomMenuItem(CustomMenuIDs[i], false);
	}
}

//当文档为保护模式的时候，需要屏蔽掉的按钮
function disableMenu_WhenProtected(){

	TANGER_OCX_EnableCustomMenuItem(CustomMenuID_AddLocalSign, false);//添加本地印章
	TANGER_OCX_EnableCustomMenuItem(CustomMenuID_AddURLSign, false);//添加远程印章
	TANGER_OCX_EnableCustomMenuItem(CustomMenuID_AddIndividualSign, false);//添加个人签名
	TANGER_OCX_EnableCustomMenuItem(CustomMenuID_AddHandSign, false);//添加手写签名
	TANGER_OCX_EnableCustomMenuItem(CustomMenuID_AddDigitalSign, false);//添加数字签名
	TANGER_OCX_EnableCustomMenuItem(CustomMenuID_ReAddDigitalSign, false);//重新数字签名
	TANGER_OCX_EnableCustomMenuItem(CustomMenuID_Separators[0], false);
	TANGER_OCX_EnableCustomMenuItem(CustomMenuID_CheckSign, false);//印章签名验证
 	TANGER_OCX_EnableCustomMenuItem(CustomMenuID_UnProtectSign, false);//取消保护
	TANGER_OCX_EnableCustomMenuItem(CustomMenuID_CheckDigitalSign, false);//验证数字签名
	TANGER_OCX_EnableCustomMenuItem(CustomMenuID_Separators[1], false);
 	TANGER_OCX_EnableCustomMenuItem(CustomMenuID_TemplateRedhead, false);//模板套红
	TANGER_OCX_EnableCustomMenuItem(CustomMenuID_ShowRevisions, false);//痕迹(显示/隐藏)
	TANGER_OCX_EnableCustomMenuItem(CustomMenuID_Separators[2], false);
 
	//自定义文件菜单
	TANGER_OCX_OBJ.RemoveFileMenuItem(0);//保存到服务器
	TANGER_OCX_OBJ.RemoveFileMenuItem(0);//从模板创建

	//文件菜单
	TANGER_OCX_EnableFileNewMenu(false);//新建
	TANGER_OCX_EnableFileOpenMenu(false);//打开

}

//根据readonly来显示按钮
function TANGER_OCX_ShowMenuByIsReadOnly() {

	TANGER_OCX_ShowMenuByID(CustomMenuID_CheckSign, true);//印章签名验证

	TANGER_OCX_ShowMenuByID(CustomMenuID_ProtectSign, false);//保护印章签名(不管什么时候都不显示)
	TANGER_OCX_ShowMenuByID(CustomMenuID_UnProtectSign, false);//取消保护
 
}

/**
 * 根据文档是否保护来显示“安全”的其它菜单
 */
function TANGER_OCX_ShowMenuByProtected() {

	if(TANGER_OCX_OBJ_GetDocType()==1){//word
		//保护
		if (TANGER_OCX_IsDocumentProtected()) {
			TANGER_OCX_ShowMenuByID(CustomMenuID_UnProtectDocument, true);
			TANGER_OCX_ShowMenuByID(CustomMenuID_ProtectDocument, false);
		}
		//未保护
		else {
			TANGER_OCX_ShowMenuByID(CustomMenuID_ProtectDocument, true);
			TANGER_OCX_ShowMenuByID(CustomMenuID_UnProtectDocument, false);
		}
	} else if (TANGER_OCX_OBJ_GetDocType()==2){//excel

		TANGER_OCX_ShowMenuByID(CustomMenuID_ProtectDocument, true);
		TANGER_OCX_ShowMenuByID(CustomMenuID_UnProtectDocument, true);
	}

}